package com.acme;

import com.acme.bankapp.domain.Bank;
import com.acme.bankapp.domain.Client;
import com.acme.bankapp.domain.Gender;
import com.acme.bankapp.domain.accounts.SavingAccount;
import com.acme.bankapp.service.BankDataLoaderService;
import com.acme.bankapp.server.BankServer;
import com.acme.bankapp.service.BankReport;
import com.acme.bankapp.service.BankService;

import java.io.*;

/**
 * Created by Student on 14.11.2014.
 */
public class BankApplication{
    public static void main(String[] args) throws IOException, InterruptedException {
        Bank bank = new Bank();

        for (int i = 0; i < args.length; i++) {
            switch (args[i]) {
                case "-loadfeed":
                    bank = BankDataLoaderService.loadBank(args[++i]);
                    break;
                case "-loadbank":
                    bank = BankService.loadBank(args[++i]);
                    break;
                case "-server":
                    new BankServer().startServer(bank);
                    break;
                default:
                    System.out.println("Incorrect parameters.");
                    return;
            }
        }

        BankService.addClient(bank, new Client("Chel1", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel2", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel3", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel4", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel5", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel6", Gender.FEMALE));
        BankService.closeListeners(bank);
        BankService.addClient(bank, new Client("Chel7", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel8", Gender.FEMALE));
        BankService.addClient(bank, new Client("Chel9", Gender.FEMALE));
        int i = 0;
        for (Client client : bank.getClients()) {
            i++;
            client.setAccount(new SavingAccount(110-i*i));
        }

        BankReport.getAccountsSortedBySum(bank);
        BankReport.getNbOfCustomers(bank);

        //BankService.printClientsInfo(bank);
    }
}